package kin.dao.security;




import org.springframework.stereotype.Component;

import kin.bean.security.Module;
import kin.dao.system.BaseManagerIMP;
import kin.manager.security.ModuleManager;

@Component
public class ModuleManagerIMP extends 
BaseManagerIMP<Module> implements ModuleManager {
	
	


	//private SessionFactory sessionFactory;
	// ok
	
	
	
	//
	/*public List<Module> findModulesByParentId(int parentId) {

		
		  List<Module> l=null; LinkedHashMap<String, Object> where=new
		  LinkedHashMap<String, Object>(); if(parentId
		 ==null||parentId.equals("root")){
		 
		  where.put("module_parent.module_id", "NULL");
		 
		try { l=this.findList(where, null); } catch (Exception e) {
	 e.printStackTrace(); }
		
		}else{ where.put("module_parent.module_id", parentId); 
		try {
		 l=this.findList(where, null); } catch (Exception e) {
			  e.printStackTrace(); }
		  }
		 
		  //return searchPaginated(hql); return l;
		 
		return null;

	}*/



	public void addOrUpdate(Module module, String parentModuleId)throws Exception {
		
		if (parentModuleId != null && parentModuleId != "") {

			Module m = this.load(parentModuleId);
			if (m != null) {
				module.setParent(m);
			} else {
				throw new Exception("");
			}
		}
		
		this.add(module);
	}



	


/*
	public List<Module> findAllParentModule() {
		 List<Module> l=null;
		
		 Criteria ca=	this.getSessionFactory().getCurrentSession().createCriteria(this.entityClass);	
		
			//ca.add(Restrictions.isNull("salary"));
			ca.add(Restrictions.or(Restrictions.isNull("method"),Restrictions.eq( "method", "GET" )));
			//ca.add(Property.forName("module_parent").isNull());
			
			l=ca.list()	;
				  //return searchPaginated(hql); return l;
		return l;
	}
*/






	


	

     



}
